# -*- coding: UTF-8 -*-
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from .models import MaintenancePlan, MaintenanceTask, MaintenanceRecord


@admin.register(MaintenancePlan)
class MaintenancePlanAdmin(admin.ModelAdmin):
    list_display = ['name', 'device', 'plan_type', 'frequency', 'next_date', 'status']
    list_display_links = ['name']
    search_fields = ['name', 'device__name', 'description']
    list_filter = ['plan_type', 'frequency', 'status', 'next_date']
    date_hierarchy = 'next_date'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'device', 'plan_type', 'description')
        }),
        (_('计划信息'), {
            'fields': ('frequency', 'start_date', 'next_date', 'status')
        }),
        (_('其他信息'), {
            'fields': ('note',),
            'classes': ('collapse',)
        }),
    )


@admin.register(MaintenanceTask)
class MaintenanceTaskAdmin(admin.ModelAdmin):
    list_display = ['task_no', 'plan', 'scheduled_date', 'assigned_to', 'status']
    list_display_links = ['task_no']
    search_fields = ['task_no', 'plan__name', 'description']
    list_filter = ['status', 'scheduled_date', 'assigned_to']
    date_hierarchy = 'scheduled_date'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('task_no', 'plan', 'scheduled_date', 'assigned_to')
        }),
        (_('任务详情'), {
            'fields': ('description', 'status', 'priority')
        }),
        (_('完成信息'), {
            'fields': ('completed_date', 'completion_notes'),
            'classes': ('collapse',)
        }),
    )


@admin.register(MaintenanceRecord)
class MaintenanceRecordAdmin(admin.ModelAdmin):
    list_display = ['record_no', 'task', 'maintenance_date', 'performed_by', 'result']
    list_display_links = ['record_no']
    search_fields = ['record_no', 'task__task_no', 'description']
    list_filter = ['result', 'maintenance_date', 'performed_by']
    date_hierarchy = 'maintenance_date'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('record_no', 'task', 'maintenance_date', 'performed_by')
        }),
        (_('维护详情'), {
            'fields': ('description', 'result', 'parts_used', 'cost')
        }),
        (_('其他信息'), {
            'fields': ('note',),
            'classes': ('collapse',)
        }),
    ) 